package com.qf.main.pharmacy.controller;

import com.qf.common.base.result.ResponseResult;
import com.qf.main.pharmacy.common.qo.OrderQo;
import com.qf.main.pharmacy.common.vo.CartVo;
import com.qf.main.pharmacy.service.CartService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chengqiang
 * @Create 2024-02-19-8:36
 * @Description:
 */
@RestController
@RequestMapping("/cart")
@CrossOrigin
@Api(tags = "购物车")
public class CartController {
    @Resource
    private CartService cartService;

    @GetMapping("/get")
    public ResponseResult<CartVo> getCartData(@RequestParam("userId") Integer userId){
        return ResponseResult.success(cartService.getCart(userId));
    }
    @DeleteMapping("/edit")
    public ResponseResult<Integer> edit(@RequestParam("mallId") Integer mallId,@RequestParam("userId") Integer userId){
        return ResponseResult.success(cartService.removeCart(userId,mallId));
    }

    @PostMapping("/place")
    public ResponseResult<Long> place(@RequestBody OrderQo orderQo){
        return ResponseResult.success(cartService.placeOrder(orderQo));
    }
}
